package com.chima.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.chima.domain.Advice;
public class AdviceDao extends HibernateDaoSupport{

	//分页查询
		@SuppressWarnings("unchecked")
		public List< Advice> findByCriteria(DetachedCriteria criteria, int firstResult,int maxResults) {
			return this.getHibernateTemplate().findByCriteria(criteria,firstResult,maxResults);
		}
	   //查找总页数
		public int findByTotalCount() {
			List list= this.getHibernateTemplate().find("select count(*) from Advice");
			long temp = (Long) list.get(0);
			return (int) temp;
		}
		public void save(Advice advice) {
			this.getHibernateTemplate().save(advice);
		}
		public void update(Advice advice) {
			this.getHibernateTemplate().update(advice);
			
		}
		
		public void delete(int id) {
			this.getHibernateTemplate().delete(this.getHibernateTemplate().load(Advice.class, id));
		}

}
